import React, {Component} from 'react';
import {RouteConfig} from "./routeConfig";
import {Route, Switch} from "react-router-dom";
import {MenuConfig} from "../pages/menu/menuConfig";
import utils from "../utils";

export default class Routers extends Component {

    render() {
        //todo 请求服务端, 读取菜单
        let menus = MenuConfig;
        //todo 遍历菜单, 结合routeConfig,设置route
        let routeTags = [];
        let routeComp;
        menus.forEach((menu) => {
            if (!menu.leaf) {
                return;
            }
            routeComp = RouteConfig[menu.path];
            if (routeComp) {
                routeTags.push(<Route key={menu.id} path={menu.path} exact component={routeComp}/>);
            }
        });

        //加上默认的
        utils.foreach(RouteConfig._inner, (path, route, inner) => {
            routeTags.push(<Route key={path} path={path} exact render={() => {
                console.log("this is test");
                return (<div>this is test</div>);
            }} component={route}/>);
        });

        return (
            <div className={"App-Content"}>
                <Switch>
                    {routeTags}
                </Switch>
            </div>
        );
    }
}
